#include "GMSetVel.h"
#include "Factory.h"
#include "Timer.h"
#include "ClientPlayerManager.h"

#include <iostream>

GMSetVel::GMSetVel()
{
	m_x = 0;
	m_y = 0;
	m_z = 0;
	m_id = 0;
}

void GMSetVel::Execute()
{
	std::cout << "GMSetVel Executed" << std::endl;
	TheCPManager::Instance()->SetClientVel(m_id, D3DXVECTOR3(m_x, m_y, m_z));
}

bool GMSetVel::Read(SocketMessage* sm)
{
	int tempTS = 0;
	sm->ReadInt(&tempTS);
	m_timeStamp = (unsigned int)tempTS;
	sm->ReadInt(&m_id);
	std::cout << "GMSetVel::Read() id: " << m_id << std::endl;
	if (sm->ReadFloat(&m_x))
	{
		std::cout << "GMSetVel::Read(): " << m_x << std::endl;
		//return true;
	}
	if (sm->ReadFloat(&m_y))
	{
		std::cout << "GMSetVel::Read(): " << m_y << std::endl;
		//return true;
	}
	if (sm->ReadFloat(&m_z))
	{
		std::cout << "GMSetVel::Read(): " << m_z << std::endl;
		return true;
	}

	return false;
}

void GMSetVel::Write(SocketMessage* sm)
{
	sm->WriteString("GMSetVel");
	sm->WriteInt(TheTimer::Instance()->GetTimeMS());
	sm->WriteInt(m_id);
	sm->WriteFloat(m_x);
	sm->WriteFloat(m_y);
	sm->WriteFloat(m_z);
}

void GMSetVel::SetVelX(float vel)
{
	m_x = vel;
}

void GMSetVel::SetVelY(float vel)
{
	m_y = vel;
}

void GMSetVel::SetVelZ(float vel)
{
	m_z = vel;
}

void GMSetVel::SetID(int id)
{
	m_id = id;
}

int GMSetVel::GetID() const
{
	return m_id;
}